/*
 * Copyright 2011 The Rusted Roof, LLC.
 *
 *    Licensed under the Apache License, Version 2.0 (the "License");
 *    you may not use this file except in compliance with the License.
 *    You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *    Unless required by applicable law or agreed to in writing, software
 *    distributed under the License is distributed on an "AS IS" BASIS,
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *    See the License for the specific language governing permissions and
 *    limitations under the License.
 */

package org.proteusframework.platformservice.messaging;

/**
 * Provides methods for publishing message beans across a message sink.
 *
 * @param <T> The type of message beans that can be published by this producer
 */
public interface IMessageSinkProducer<T extends IMessageBean> extends IMessageSinkClient<T>
{
    /**
     * Attempts to deliver the message to the backing message sink implementation.
     *
     * @param message Message bean
     * @return true, if the message was successfully delivered, or false otherwise
     * @throws NullPointerException     if the message is null
     * @throws IllegalArgumentException if the backing message sink determines it cannot accept the message as
     *                                  a result of the message's internal state or definition, as described by the beans corresponding
     *                                  {@link org.proteusframework.platformservice.persistence.api.messagebean.IMessageBeanDescriptor} within
     *                                  the {@link org.proteusframework.platformservice.persistence.api.IPersistenceService}.
     */
    boolean offerMessage(T message);


    /**
     * Immediately delivers the message to the backing message sink implementation, waiting if necessary
     * for the sink to become available.
     *
     * @param message Message bean
     * @throws NullPointerException     if the message is null
     * @throws IllegalArgumentException if the backing message sink determines it cannot accept the message as
     *                                  a result of the message's internal state or definition, as described by the beans corresponding
     *                                  {@link org.proteusframework.platformservice.persistence.api.messagebean.IMessageBeanDescriptor} within
     *                                  the {@link org.proteusframework.platformservice.persistence.api.IPersistenceService}.
     * @throws InterruptedException     if interrupted while waiting
     */
    void publishMessage(T message) throws InterruptedException, IllegalArgumentException;
}
